package books;

import org.joda.time.DateTime;

import users.Person;
import util.Entity;
import builders.BookReservationBuilder;

/**
 * Denotes the reservation of a book
 */
public class BookReservation extends Entity {

    private static final long serialVersionUID = 1L;

    private BookInfo book;

    private Person person;

    private DateTime date;

    private DateTime copyReturnedDate;

    private Book reservedCopy;

    private boolean satisfied;

    public BookReservation(final BookInfo aBookInfo, final Person aPerson) {
        super();
        this.book = aBookInfo;
        this.person = aPerson;
        this.date = new DateTime();
        this.satisfied = false;
    }

    public BookReservation() {
        super();
        // empty constructor
    }

    public BookReservation(final BookReservationBuilder builder) {
        super();
        this.book = builder.getBook();
        this.copyReturnedDate = builder.getCopyReturnedDate();
        this.date = builder.getDate();
        this.person = builder.getPerson();
        this.satisfied = builder.isSatisfied();
        this.reservedCopy = builder.getReservedCopy();
    }

    public void setBook(final BookInfo book) {
        this.book = book;
    }

    public BookInfo getBook() {
        return this.book;
    }

    public void setPerson(final Person person) {
        this.person = person;
    }

    public Person getPerson() {
        return this.person;
    }

    public void setDate(final DateTime date) {
        this.date = date;
    }

    public DateTime getDate() {
        return this.date;
    }

    public void copyReturned() {
        this.setCopyReturnedDate(DateTime.now());
    }

    public void setCopyReturnedDate(final DateTime copyReturnedDate) {
        this.copyReturnedDate = copyReturnedDate;
    }

    public DateTime getCopyReturnedDate() {
        return this.copyReturnedDate;
    }

    public void setReservedCopy(final Book reservedCopy) {
        this.reservedCopy = reservedCopy;
    }

    public Book getReservedCopy() {
        return this.reservedCopy;
    }

    public void reserveCopy(final Book aCopy) {
        this.setReservedCopy(aCopy);
        this.setCopyReturnedDate(DateTime.now());
        this.setSatisfied(true);
    }

    public void setSatisfied(final boolean satisfied) {
        this.satisfied = satisfied;
    }

    public boolean isSatisfied() {
        return this.satisfied;
    }

}
